#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int mx1[maxn],mx2[maxn];
int sumOfBeauties(vector<int>& nums) {
    bool flag1=true;
    int n=nums.size();
    int ans=0;
    memset(mx1,0,sizeof(mx1));memset(mx2,0x3f,sizeof(mx2));
    for(int i=0;i<nums.size();i++)
    {
        mx1[i]=max(mx1[i-1],nums[i]);
    }
    for(int i=nums.size()-1;i>=0;i--)
    {
        mx2[i]=min(mx2[i+1],nums[i]);
    }
    for(int i=1;i<=n-2;i++)
    {
        if(nums[i]>mx1[i-1]&&nums[i]<mx2[i+1])  ans+=2;
        else if(nums[i]>nums[i-1]&&nums[i]<nums[i+1]) ans++;
    }
    return ans;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);

   	return 0;
}
